package com.itzhigui.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 统一返回给前端的工具类
 *
 * @author java1412
 * @since 2023-11-09 14:19:26
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ResponseUtil implements Serializable {

    private Integer code;
    private String msg;
    private Object data;

    /**
     * 带有数据的状态
     *
     * @param responseEnum
     * @param obj
     * @return
     */
    public static ResponseUtil get(ResponseEnum responseEnum, Object obj) {
        return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg(), obj);
    }

    /**
     * 不带有数据的状态
     *
     * @param responseEnum
     * @return
     */
    public static ResponseUtil get(ResponseEnum responseEnum) {
        return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg(), null);
    }
}
